package com.swust.exam.controller;


import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;



import org.springframework.web.bind.annotation.PutMapping;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.swust.exam.pojo.Course;
import com.swust.exam.service.CourseService;

@Controller
@RequestMapping("/course")
public class CourseController {
	
	@Autowired
	private CourseService courseService;
	
	
	@RequestMapping(value="/get")
	public Course courseGet(Integer id) {
		return courseService.get(id);
	}
	
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String courseDelete(Integer id ,Model model) {
		 courseService.delete(id);
		 List<Course> list=courseService.courselist();
		 model.addAttribute("courselist",list);
		return "course";
	}
	
	@RequestMapping(value="/insert")
	
	public String courseInsert(Course course,Model model) {

		
		 courseService.insert(course);
		 List<Course> list=courseService.courselist();
		 model.addAttribute("courselist",list);
		 return "course";
	
	}
	 
	@PutMapping(value="/update")
	public int courseUpdate(Course course){
		
		return courseService.update(course);
	}
	

}
